
package com.woniuxy.woniuhis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.woniuhis.entity.Dep;
import com.woniuxy.woniuhis.exception.DepServiceException;
import com.woniuxy.woniuhis.mapper.DepMapper;
import com.woniuxy.woniuhis.service.DepService;

@Service
public class DepServiceImpl implements DepService{
	
	@Autowired
	DepMapper depMapper;
	
	@Override
	public void addDep(Dep dep) {
		try {
			depMapper.insertDep(dep);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
		
	}

	@Override
	public void modifyDepInfo(Dep dep) {
		try {
			depMapper.updateDepInfo(dep);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
	}

	@Override
	public void delDepInfoByDepId(String depId) {
		try {
			depMapper.deleteDepInfoByDepId(depId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
		
	}

	@Override
	public PageInfo<Dep> findAlldep(Dep dep,Integer pageIndex,Integer pageSize) {
		try {
			PageHelper.startPage(pageIndex, pageSize);
			List<Dep> list = depMapper.selectAlldep(dep);
			return new PageInfo<>(list);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
	}

	@Override
	public Dep findDepBydepId(String depId) {
		try {
			return depMapper.selectDepBydepId(depId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
	}

	@Override
	public List<Dep> findAlldep() {
		try {
			return depMapper.selectAlldep();
		} catch (Exception e) {
			e.printStackTrace();
			throw new DepServiceException("系统维护中");
		}
	}

}
